%% Smoothed Probabilities Function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [pr_sm1,pr_sm2,pr_sm3] = smoothed_probs(prmtr,T,pr_tt1,pr_tt2,pr_tt3,pr_tl1,pr_tl2,pr_tl3)

           
           % Parameters, where regimes: 0 normal; 1 L-shaped recession; 2 U-shaped recession 

           p01 = prmtr(1);      %Pr[St=1|St-1=0]
           p02 = prmtr(2);      %Pr[St=2|St-1=0]
           p11 = prmtr(3);      %Pr[St=1|St-1=1]
           p22 = prmtr(4);      %Pr[St=2|St-1=2]  
           
           
           % A MATRIX OF TRANSITION PROBABILITIES 

           PI = [1-p01 - p02, 1-p11, 1-p22;
                    p01, p11, 0;
                    p02, 0, p22];
           

      
      p11 = PI(1,1); p12 = PI(2,1); p13 = PI(3,1);
      p21 = PI(1,2); p22 = PI(2,2); p23 = PI(3,2);
      p31 = PI(1,3); p32 = PI(2,3); p33 = PI(3,3);

           pr_sm1 = pr_tt1;     % pr_sm will contain Pr[S_t|Y_T]
           pr_sm2 = pr_tt2;
           pr_sm3 = pr_tt3;

        j_iter = T-1;
        while j_iter >= 1

    %The following are P[S_t, S_t+1|Y_T]

   pr_sm11 = pr_sm1(j_iter+1,1)*p11*pr_tt1(j_iter,1)/pr_tl1(j_iter+1,1);
   pr_sm12 = pr_sm2(j_iter+1,1)*p12*pr_tt1(j_iter,1)/pr_tl2(j_iter+1,1);
   pr_sm13 = pr_sm3(j_iter+1,1)*p13*pr_tt1(j_iter,1)/pr_tl3(j_iter+1,1);

   pr_sm21 = pr_sm1(j_iter+1,1)*p21*pr_tt2(j_iter,1)/pr_tl1(j_iter+1,1);
   pr_sm22 = pr_sm2(j_iter+1,1)*p22*pr_tt2(j_iter,1)/pr_tl2(j_iter+1,1);
   pr_sm23 = pr_sm3(j_iter+1,1)*p23*pr_tt2(j_iter,1)/pr_tl3(j_iter+1,1);

   pr_sm31 = pr_sm1(j_iter+1,1)*p31*pr_tt3(j_iter,1)/pr_tl1(j_iter+1,1);
   pr_sm32 = pr_sm2(j_iter+1,1)*p32*pr_tt3(j_iter,1)/pr_tl2(j_iter+1,1);
   pr_sm33 = pr_sm3(j_iter+1,1)*p33*pr_tt3(j_iter,1)/pr_tl3(j_iter+1,1);

   pr_sm1(j_iter,1) = pr_sm11 + pr_sm12 + pr_sm13;
   pr_sm2(j_iter,1) = pr_sm21 + pr_sm22 + pr_sm23;
   pr_sm3(j_iter,1) = pr_sm31 + pr_sm32 + pr_sm33;

        j_iter = j_iter - 1;
        end              
    
end % End of smoother